package com.ohs.ohsoa.system.controller;


import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.ohs.ohsoa.system.dto.WorkNotesDto;
import com.ohs.ohsoa.system.service.WorkNotesService;
import com.ohs.ohsoa.system.vo.WorkNotesNumberVo;
import com.ohs.ohsoa.system.vo.WorkNotesVo;
import com.ohs.ohsoa.utils.auth.UserLoginToken;
import com.ohs.ohsoa.utils.bean.requestBean.PageParam;
import com.ohs.ohsoa.utils.bean.responseBean.ResultBean;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 工作笔记Controller
 *
 * @author zhangjy
 *
 */

@Api(value = "工作笔记", tags = "工作笔记")
@RestController
@RequestMapping("/worknotes")
public class WorkNotesController {
    @Resource
    private WorkNotesService workNotesService;

    /**
     * 获取工作笔记列表信息
     *
     * @param pageParam 检索用参数
     * @return 工作笔记列表信息
     *
     */
    @UserLoginToken
    @PostMapping(value = "/select/list")
    @ApiOperation(httpMethod = "POST", value = "获取工作笔记列表信息")
    public ResultBean<PageInfo<WorkNotesVo>> WorkNotesSelectList(@RequestBody PageParam<WorkNotesDto> pageParam) {
        List<WorkNotesVo> res = workNotesService.workNotesSelectList(pageParam);
        return ResultBean.success(new PageInfo<>(res));
    }


    /**
     * 根据id获取工作笔记详细信息
     *
     * @param workNotesDto 工作笔记列表信息数据
     * @return 工作笔记列表信息
     *
     * workNotesGuid必传
     */
    @UserLoginToken
    @PostMapping(value = "/select")
    @ApiOperation(httpMethod = "POST", value = "根据id获取工作笔记详细信息")
    public ResultBean<WorkNotesVo> workNotesSelect(@RequestBody WorkNotesDto workNotesDto) {
        return ResultBean.success(workNotesService.workNotesSelect(workNotesDto));
    }

    /**
     * 新增工作笔记
     *
     * @param workNotesDto 工作笔记数据
     * @return 新增结果
     */
    @UserLoginToken
    @PostMapping(value = "/insert")
    @ApiOperation(httpMethod = "POST", value = "新增工作笔记")
    public ResultBean<Boolean> workNotesInsert(@RequestBody @Valid WorkNotesDto workNotesDto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(workNotesService.workNotesInsert(workNotesDto));
    }


    /**
     * 删除工作笔记
     *
     * @param workNotesDto 工作笔记数据
     * @return 删除结果
     */
    @UserLoginToken
    @DeleteMapping(value = "/delete")
    @ApiOperation(httpMethod = "DELETE", value = "批量删除工作笔记")
    public ResultBean<Boolean> workNotesDelete(@RequestBody WorkNotesDto workNotesDto) {
        return ResultBean.success(workNotesService.workNotesDelete(workNotesDto));
    }


    /**
     * 修改工作笔记
     *
     * @param workNotesDto 工作笔记数据
     * @return 修改结果
     */
    @UserLoginToken
    @PutMapping(value = "/update")
    @ApiOperation(httpMethod = "PUT", value = "修改工作笔记")
    public ResultBean<Boolean> workNotesUpdate(@RequestBody @Valid WorkNotesDto workNotesDto, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultBean.fail(bindingResult.getAllErrors().get(0).getDefaultMessage());
        }
        return ResultBean.success(workNotesService.workNotesUpdate(workNotesDto));
    }

    /**
     * 工作日报数量
     *
     * @param workNotesDto 工作日报数量
     * @return 工作日报数量
     */
    @UserLoginToken
    @PostMapping(value = "/number")
    @ApiOperation(httpMethod = "POST", value = "工作日报数量")
    public ResultBean<List<WorkNotesNumberVo>> worktypeSelect(@RequestBody WorkNotesDto workNotesDto) {
        return ResultBean.success(workNotesService.worktypeSelect(workNotesDto));
    }
}
